package com.like.miaosha.controller;

import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement;
import com.like.miaosha.result.CodeMsg;
import com.like.miaosha.result.Result;
import com.like.miaosha.service.MiaoshaUserService;
import com.like.miaosha.service.UserService;
import com.like.miaosha.util.ValidatorUtil;
import com.like.miaosha.vo.LoginVo;
import jdk.nashorn.internal.ir.RuntimeNode;
import org.apache.tomcat.util.codec.binary.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.java2d.pipe.SpanIterator;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
@RequestMapping("/login")
public class LoginController {
    @Autowired
    MiaoshaUserService miaoshaUserService;
    private static Logger log= LoggerFactory.getLogger(LoginController.class);



    @RequestMapping("/to_login")
    public String login() {

        return "login";
    }



    @RequestMapping("/do_login")
    @ResponseBody
    public Result<String> doLogin(HttpServletResponse resp, @Valid LoginVo loginVo){
        //log.info(loginVo.toString());

        String token=miaoshaUserService.login(resp,loginVo);

        return Result.success(token);
    }
}
